import numpy as np

# 定义一个矩阵
A = np.array([[4, -2],
              [1, 1]])

# 计算特征值和特征向量
eigenvalues, eigenvectors = np.linalg.eig(A)

# 打印特征值
print("\n")
print("特征值:")
print(eigenvalues)

# 打印特征向量
print("特征向量:")
print(eigenvectors)

# 验证特征向量
for i in range(len(eigenvalues)):
    # Eigenvector * eigenvalue = A * eigenvector
    # 计算 A * eigenvector
    result = np.dot(A, eigenvectors[:, i])
    print(f"A * 特征向量 {i + 1}:")
    print(result)
    # 计算 eigenvalue * eigenvector
    expected_result = eigenvalues[i] * eigenvectors[:, i]
    print(f"特征值 {i + 1} * 特征向量 {i + 1}:")
    print(expected_result)
    print("验证结果:", np.allclose(result, expected_result))
    print("---------------")